#ifndef _aky_define_H
#define _aky_define_H

typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long int uint32_t;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef enum {FALSE = 0, TRUE = 1} BOOL;

typedef uint8_t int8_t;
typedef uint16_t  int16_t;
typedef uint32_t  int32_t;


#define	Pin_0                      ((uint8_t)0x01)
#define	Pin_1                      ((uint8_t)0x02)
#define	Pin_2                      ((uint8_t)0x04)
#define	Pin_3                      ((uint8_t)0x08)
#define	Pin_4                      ((uint8_t)0x10)
#define	Pin_5                      ((uint8_t)0x20)
#define	Pin_6                      ((uint8_t)0x40)
#define	Pin_7                      ((uint8_t)0x80)
#define	Pin_ALL                    ((uint8_t)0xFF)

#define	GPIO0                   0
#define	GPIO1                   1
#define	GPIO2                   2
#define	GPIO3                   3
#define	GPIO4                   4
#define	GPIO5                   5

#define	CHAR_P               P
#define	CHAR_M               M
#define	CHAR_UR              UR
#define _LINK2(A,B) A##B
#define LINK2(A,B) _LINK2(A,B)//预处理  2个字符连接成一个 传参都要是宏定义
#define _LINK3(A,B,C) A##B##C
#define LINK3(A,B,C) _LINK3(A,B,C) //预处理  3个字符连接成一个 传参都要是宏定义

#define  RXEnable								REN0=1							//RXD Enable
#define  RXDisable							REN0=0							//RXD Disable
#define  RXIEnable							ES0=1								//RXD Interrupt enable
#define  RXIDisable							ES0=0								//RXD Interrupt disable

#define	 ADEnable								ADCM1 |= 0x01;
#define	 ADDisable							ADCM1 &= 0xFE;
#define	 TC2Enable						  IEN2	|= 0x08;
#define	 TC2Disable						  IEN2	&= 0xF7;
#define	 I2CDisable							I2CCON&= 0xBF;
#define	 I2CEnable							I2CCON|= 0x40;

#define	 SCIdleMode							PCON |= 0x01; 	//IDLE MODE
#define	 SCStopMode							PCON |= 0x02; 	//STOP MODE
#define	 SCIdleMode							PCON |= 0x01; 	//IDLE MODE
#define	 SCStopMode							PCON |= 0x02; 	//STOP MODE


typedef struct
{
    uint8_t year : 7;  //
    uint8_t month : 4; //
    uint8_t day : 5;   //
    uint8_t hour : 5;  //
    uint8_t min : 6;   //
} s_time_t;            // 时间


typedef struct
{
    uint8_t flag_power_on : 1;       // 开机状态标志位
    uint8_t flag_one_shot : 1;       //
    uint8_t flag_rtc_it_trig : 1;    //
    uint8_t cuff_ok_flag : 1;        //
    uint8_t flag_cuff_loose : 1; //
    uint8_t flag_cuff_onece_set : 1; //
    uint8_t flag_emc_mode : 1; //
    uint8_t flag_low_bat_trig : 1; //
    uint8_t flag_disp_loop_ongoing : 1; //
    uint8_t T125Flag : 1; //
    uint8_t T1Flag : 1; //
    uint8_t flag_timer_10ms : 1; //
    uint8_t flag_adc_ok : 1; //

} s_flag_group_t; // 每次进入低功耗模式都会清零
extern volatile s_flag_group_t g_s_flag_group;
#define IsPowerOn (g_s_flag_group.flag_power_on)
#define flag_cuff_ok (g_s_flag_group.cuff_ok_flag)         //
#define flag_cuff_loose (g_s_flag_group.flag_cuff_loose)      //
#define flag_cuff_onece_set (g_s_flag_group.flag_cuff_onece_set) //
#define flag_emc_mode (g_s_flag_group.flag_emc_mode) //
#define T125Flag (g_s_flag_group.T125Flag) //
#define T1Flag (g_s_flag_group.T1Flag) //
#define flag_timer_10ms (g_s_flag_group.flag_timer_10ms) //
#define flag_adc_ok (g_s_flag_group.flag_adc_ok) //


typedef struct
{
    uint8_t flag_key_power : 1; //
    uint8_t flag_key_set : 1;   //
    uint8_t flag_key_mem : 1;   //
} s_flag_group_const_t;         // 不自动清零
extern volatile s_flag_group_const_t g_s_flag_group_const;

typedef volatile union word_data
{
    uint16_t w;
    uint8_t b[2];
} word_data;

typedef enum
{
    PRES_100_ACCURACY = 0, // 100位精度 个位
    PRES_1000_ACCURACY,    // 1000位精度 0.1
} e_pres_t;                // 压力计算精度选择

typedef volatile union dword_data
{
    uint32_t l;
    uint16_t w[2];
    uint8_t b[4];
} dword_data;

extern volatile union word_data SensorCount;
#define SensorCountw SensorCount.w
#define SensorCount2b SensorCount.b[0]
#define SensorCount1b SensorCount.b[1]

extern volatile union word_data ZeroCount;
#define ZeroCountw ZeroCount.w
#define ZeroCount2b ZeroCount.b[0]
#define ZeroCount1b ZeroCount.b[1]

extern volatile union dword_data Math;
#define Mathhw Math.w[0]
#define Math04b Math.b[0]
#define Math03b Math.b[1]
#define Mathlw Math.w[1]
#define Math02b Math.b[2]
#define Math01b Math.b[3]

extern volatile union dword_data TemplateValue;
#define TemplateValueLong TemplateValue.l
#define TemplateValuehw TemplateValue.w[0]
#define TemplateValue04b TemplateValue.b[0]
#define TemplateValue03b TemplateValue.b[1]
#define TemplateValuelw TemplateValue.w[1]
#define TemplateValue02b TemplateValue.b[2]
#define TemplateValue01b TemplateValue.b[3]

extern volatile union word_data PressuremmHg;
#define PressuremmHgw PressuremmHg.w
#define PressuremmHg2b PressuremmHg.b[0]
#define PressuremmHg1b PressuremmHg.b[1]

typedef enum
{
    FIRST_UP_MODE = 0, // 首次上电
    STOP_MODE,         // 低功耗
    LINEAR_MODE,       // 线性
    CAL_MODE,          // 手动校压
    START_TEST_MODE,   // 开始测试
    MEM_MODE,          // 查记忆
    SET_MODE,          // 设定模式
    LOW_BAT_MODE,      // 低电压界面
    CHARGE_MODE,       // 充电界面
    FAST_TEST_MODE,    // 生产用快速测试界面
    MENU_SEL_MODE,    // 选择菜单
    LEAK_TEST_MODE,    // 
    AIR_TIGHT_TEST_MODE,    // 
    INFLAT_DEFLAT_TIME_TEST_MODE,
    PRES_METER_MODE,    // 压力表模式

} e_sys_stat_t;        // 系统状态机

#define MAX_PRESURE (399ul)// 最大mmgh上限 

#define OFF_TIME (300ul)
#define AKY_ASM_NOP() _nop_()

#endif //